package com.rabbitmq.dead;

import com.rabbitmq.client.*;
import com.rabbitmq.util.ConnectionUtils;

import java.io.IOException;

/**
 * @author yinxing
 * @date 2022-08-30
 * 消费死信队列
 */
public class DeadConsumer {

    private final static String DEAD_EXCHANGE = "dead_exchange";

    private final static String DEAD_ROUTE_KEY = "dead_key";

    private final static String DEAD_QUEUE_NAME = "dead_queue";

    public static void main(String[] args) throws IOException {
        Channel channel = ConnectionUtils.getChannel();
        DeliverCallback deliverCallback = (String consumerTag, Delivery message) ->{
            System.out.println("死信接收到消息:" + new String(message.getBody()));
            /**
             * 1、消息标识
             * 2、是否批量应答
             */
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };
        channel.basicConsume(DEAD_QUEUE_NAME,false, deliverCallback, (String consumerTag) ->{} );


    }
}
